// 1. Option是标准库定义的一个枚举，形式：
//
// enum Option<T>{
//
// ​	Some(T),
//
// ​	None,
//
// }

fn main() {
    let some_number = Some(2);
    let some_string = Some(String::from("xiaoming"));

    let absent_number:Option<i32> = None;

    let x:i32 = 5;
    let y:Option<i32> = Some(5);
    let mut temp = 0;
    match y {
        Some(i) => { temp = i; },
        None => { println!("do nothing");}
    }

    let sum = x + temp;
    println!("sum = {}",sum);


    let result = plus_one(y);
    //match处理Option类型，必须把所有情况处理完（None）
    match result {
        None => {println!("nothing")},
        Some(i) => println!("result = {}",i),
    }

    //if处理
    // 没搞懂用let..
    if let Some(value) = plus_one(y){
        println!("value = {}",value);
    }



    println!("Hello, world!");
}

fn plus_one(x:Option<i32>) -> Option<i32>{
    match x {
        None => None,
        Some(i) => {Some(i+1)}
    }
}
